/**
 * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
 * <p>
 * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.gnu.org/licenses/lgpl.html
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.springblade.modules.monitor.controller;

import io.swagger.annotations.Api;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import javax.validation.Valid;

import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.monitor.dto.ChainRelationshipDTO;
import org.springblade.modules.monitor.dto.ChainSourceDTO;
import org.springblade.modules.monitor.entity.ChainSource;
import org.springblade.modules.monitor.service.IChainSourceService;
import org.springblade.modules.monitor.vo.ChainRelationshipVO;
import org.springblade.modules.monitor.vo.ChainSourceVO;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.boot.ctrl.BladeController;

/**
 *  控制器
 *
 * @author Blade
 * @since 2020-08-18
 */
@RestController
@AllArgsConstructor
@RequestMapping("blade-monitor/chainsource")
@Api(value = "链路源信息", tags = "链路源信息")
public class ChainSourceController extends BladeController {

	private IChainSourceService chainSourceService;

	/**
	 * 自定义分页
	 */
	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分页", notes = "传入ChainSourceVO")
	public R<IPage<ChainSourceVO>> page(ChainSourceDTO chainSourceDTO, Query query) {
		ChainSourceVO chainSourceVO = new ChainSourceVO();
		BeanUtils.copyProperties(chainSourceDTO, chainSourceVO);
		IPage<ChainSourceVO> pages = chainSourceService.selectChainSourcePage(Condition.getPage(query), chainSourceVO);
		return R.data(pages);
	}


	/**
	 * 新增或修改
	 */
	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "新增或修改", notes = "传入chainSource")
	public R submit(@Valid @RequestBody ChainSource chainSource) {
		return R.status(chainSourceService.saveOrUpdate(chainSource));
	}


	/**
	 * 删除
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 8)
	@ApiOperation(value = "删除", notes = "传入ids")
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.status(chainSourceService.removeByIds(Func.toLongList(ids)));
	}


}
